var out = document.getElementById("saida");
$(".parent-op-top-menu").hover(function(){	
	$(this).addClass("parent-op-top-menu-hover fnt-white");
	var lis = $(this).children(".sub-menu");
	$(lis).stop(true, true).slideToggle(200);	
}, function() {
	var lis = $(this).children(".sub-menu");
	$(lis).stop(true, true).slideToggle("fast");	
	$(this).removeClass("parent-op-top-menu-hover fnt-white");
});

$(".sub-menu-item").hover(function(){
	$(this).addClass("green2-grad-back fnt-white");
}, function() {
	$(this).removeClass("green2-grad-back fnt-white");
});
$(function(){
    $(".ask").click(function(){
        if(!confirm("Deseja realmente "+$(this).attr("ask")+"?")){
            event.preventDefault();
            event.returnValue = false;
            return false;
        } 
    });

    $("#logout-btn").hover(function(){
        $(this).addClass("brown-grad-back fnt-white");
    }, function(){
        $(this).removeClass("brown-grad-back fnt-white");
    }); 
});

var els = document.getElementsByClassName("selectable");
for(i = 0, len = els.length; i < len; i++){
	els[i].onclick = function(){
		var op = this.getAttribute("op");
		window.location = "?op="+op;	
	} 
}

function removeChilds(e){
	while(e.firstChild){
		e.removeChild(e.firstChild);
	}
}

function alert(msg, isBad){
        if(!isBad) $("#alert").removeClass("brown-grad-back");
        msg = msg.replace(/\n/g, "<br>");
	document.getElementById("content-alert").innerHTML = msg;
	if(!$("#alert" ).is(":visible")){
		$("#alert").slideToggle("fast");
	}
}
function badAlert(msg){
        $("#alert").addClass("brown-grad-back");
        alert("<b class='fnt-white'>"+msg+"</b>", true);
}
function closeAlert(){
	$("#alert").slideToggle("fast");
} 

function post (url, param, success) {
    $.ajax({
        type: "POST",
        url : url,
        dataType: 'json',
        data: param,    
        success: success,
        error: function (a, b, c) { badAlert(a+"\n"+b+"\n"+c); }
    });
}

function get (url, success) {
	$.ajax({
            type: "GET",
            url : url,
            dataType: 'json',  
            success: success
    });
}
function postHTML (url, param, success) {
    $.ajax({
        type: "POST",
        url : url,
        dataType: 'html',
        data: param,    
        success: success,
        error: function (a, b, c) { badAlert(a+"\n"+b+"\n"+c); }
    });
}

function getHTML (url, success) {
	$.ajax({
            type: "GET",
            url : url,
            dataType: 'html',  
            success: success
    });
}
function clearForm(form_id){
    $("#"+form_id+" input").val("");
    $("#"+form_id+" select").val("");
}
function openViewDataMode(serv){
    getHTML(serv, function(data){
        if(data != "") {
            $("#view-data-back .content").html(data);
            //$("#body").css({overflow:"hidden"});
            $("#view-data-back").fadeIn("fast");
        }
    });
   
}
function closeViewDataMode(){
    $("#view-data-back").fadeOut("fast");
    $("#view-data-back .content").html("");
    //$("#body").css({overflow:"auto"});
}